#!/bin/bash

# 批量启动一主二备拓扑的安装模式

set -e

SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SOURCE_DIR/config.conf"

echo "启动一主二备拓扑安装模式..."
echo

# 定义节点
NODES=("${VM_NAME_PREFIX}-master1" "${VM_NAME_PREFIX}-worker1" "${VM_NAME_PREFIX}-worker2")

for vm_name in "${NODES[@]}"; do
    install_script="$VM_IMAGE_DIR/install-${vm_name}.sh"
    if [ -f "$install_script" ]; then
        echo "启动 $vm_name 安装模式..."
        "$install_script"
        echo "$vm_name 安装模式已启动"
    else
        echo "警告: $install_script 不存在"
    fi
    echo
done

echo "所有虚拟机安装模式已启动"
echo "请通过VNC客户端连接各虚拟机完成系统安装:"
echo
for vm_name in "${NODES[@]}"; do
    info_file="$VM_IMAGE_DIR/${vm_name}.info"
    if [ -f "$info_file" ]; then
        vnc_port=$(grep "VNC_PORT=" "$info_file" | cut -d'=' -f2)
        echo "$vm_name: VNC端口 $vnc_port (localhost:$vnc_port)"
    fi
done
